package org.paul

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView

class ConfigAdapter : ListAdapter<String,ConfigVH>(
    object :DiffUtil.ItemCallback<String>(){
        override fun areItemsTheSame(oldItem: String, newItem: String): Boolean {
            return oldItem == newItem
        }

        override fun areContentsTheSame(oldItem: String, newItem: String): Boolean {
            return oldItem == newItem
        }

    }
) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ConfigVH {
        val inflate = LayoutInflater.from(parent.context).inflate(R.layout.item_single_content, parent, false)
        return ConfigVH(inflate)
    }

    override fun onBindViewHolder(holder: ConfigVH, position: Int) {
        holder.bind(getItem(position),position)
    }
}
class ConfigVH(itemView: View) :RecyclerView.ViewHolder(itemView){
    fun bind(item: String?, position: Int) {
        itemView.findViewById<AppCompatTextView>(R.id.content).text = item?:"请检查你的代码，竟然有这种错误"
    }

}